var goodsData;	   
var isFromStationClick = false;	
var isToStationClick = false;
var isSaleTypeClick = false;
var isPaywayClick = false;
var isDeliverywayClick = false;
var isShipmentClick = false;
var addNo =10000;
var addFeeNo =10000;
var selectRow ;
var	selectCell;
var selectTR;
var goodsIDArray;
var sizeArray;
var weightArray;
var qtyArray;
var unitArray ;
var	volumeArray ;
var	grossWeightArray ;
var	feeItemIDArray ;//存放费用ID数组
var	amountArray ;//存放费用金额数组
var	noteArray ;//存放备注数组
var url;
var status;
var saleID;
			
$(document).ready(function(){
	setUrl();
	setTitle();
	$('#back').click(function(){
		$('#content', parent.document).attr("src",js+"sale.action");
		return false;				 
	})
	$('#confirmOK').click(function(){
		var saleID = $('#saleID').val();
		$.post(js+'sale/updateStatusSale.action',{saleID:saleID,status:1},function(result){
		     if(result.success){
		     		$('#confirmOK').hide();	
					$('#unConfirmOK').show();
					$('#status').val(1);
					status='1';
					$('#statusStr').val('确认');
					$('#save').linkbutton({disabled:true})
		      }else{
		          $.messager.alert('提示',"确认托运单不成功!!!","error");	
		      }
		},"json");
		return false;				 
	})
	
	$('#unConfirmOK').click(function(){
		var saleID = $('#saleID').val();
		$.post(js+'sale/updateStatusSale.action',{saleID:saleID,status:0},function(result){
		     if(result.success){
		     		$('#confirmOK').show();	
					$('#unConfirmOK').hide();
					$('#status').val(0);
					status='0';
					$('#statusStr').val('未确认');
					$('#save').linkbutton({disabled:false})
		      }else{
		          $.messager.alert('提示',"取消确认托运单不成功!!!","error");	
		      }
		},"json");
		return false;				 
	})
	
	$('#fromStation').click(function(){
		if(isFromStationClick){
			return;
		}
		isFromStationClick =true;
		var value =$(this).val();
		$('#fromStation').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:500,
			width:435,
			idField:'stationID',
			textField:'stationName',
			url:js+'station/chooseStation.action',
			columns:[[
				{field:'stationCode',title:'网点编号',width:100},
				{field:'stationName',title:'网点名称',width:100},
				{field:'manager',title:'负责人',width:100},
				{field:'contact',title:'联系人',width:100},
				{field:'cityName',title:'地域城市',width:100},
				{field:'telephone',title:'联系方式',width:100},
				{field:'address',title:'地址',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if(row.stationCode.toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#fromStation').combogrid('clear');  $('#fromStationID').val('');  $('#cityName').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#fromStation').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var cityID = $('#fromStation').combogrid('getValue');
					var hidden = $('#fromStationID').val();
					if(hidden==cityID||cityID==''){
						return;
					}
					$('#fromStationID').val(cityID);
					$('#fromStation').val($('#fromStation').combogrid('getText'));
			    }
		});	
		$('#fromStation').combogrid('setText',value);
	})
	
	$('#toStation').click(function(){
		if(isToStationClick){
			return;
		}
		isToStationClick =true;
		var value =$(this).val();
		$('#toStation').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:500,
			width:435,
			idField:'stationID',
			textField:'stationName',
			url:js+'station/chooseStation.action',
			columns:[[
				{field:'stationCode',title:'网点编号',width:100},
				{field:'stationName',title:'网点名称',width:100},
				{field:'manager',title:'负责人',width:100},
				{field:'contact',title:'联系人',width:100},
				{field:'cityName',title:'地域城市',width:100},
				{field:'telephone',title:'联系方式',width:100},
				{field:'address',title:'地址',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if(row.stationCode.toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#toStation').combogrid('clear');  $('#toStationID').val('');  $('#cityName').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#toStation').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var cityID = $('#toStation').combogrid('getValue');
					var hidden = $('#toStationID').val();
					if(hidden==cityID||cityID==''){
						return;
					}
					$('#toStationID').val(cityID);
					$('#toStation').val($('#toStation').combogrid('getText'));
			    }
		});	
		$('#toStation').combogrid('setText',value);
	})	
	
	
	$('#saleType').click(function(){
		if(isSaleTypeClick){
			return;
		}
		isSaleTypeClick =true;
		var value =$(this).val();
		$('#saleType').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:400,
			width:260,
			idField:'dictionaryID',
			textField:'dictionaryName',
			url:js+'dict/chooseDictionary.action?type=saleType',
			columns:[[
				{field:'dictionaryCode',title:'业务类型编号',width:100},
				{field:'dictionaryName',title:'业务类型名称',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if((row.dictionaryCode+row.dictionaryName).toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#saleType').combogrid('clear');  $('#saleTypeID').val('');  $('#saleType').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#saleType').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var saleTypeID = $('#saleType').combogrid('getValue');
					var hidden = $('#saleTypeID').val();
					if(hidden==saleTypeID||saleTypeID==''){
						return;
					}
					$('#saleTypeID').val(saleTypeID);
			    }
		});	
		$('#saleType').combogrid('setText',value);
	})
	
	$('#payway').click(function(){
		if(isPaywayClick){
			return;
		}
		isPaywayClick =true;
		var value =$(this).val();
		$('#payway').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:400,
			width:260,
			idField:'dictionaryID',
			textField:'dictionaryName',
			url:js+'dict/chooseDictionary.action?type=payway',
			columns:[[
				{field:'dictionaryCode',title:'结算方式编号',width:100},
				{field:'dictionaryName',title:'结算方式名称',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if((row.dictionaryCode+row.dictionaryName).toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#payway').combogrid('clear');  $('#paywayID').val('');  $('#payway').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#payway').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var paywayID = $('#payway').combogrid('getValue');
					var hidden = $('#paywayID').val();
					if(hidden==paywayID||paywayID==''){
						return;
					}
					$('#paywayID').val(paywayID);
			    }
		});	
		$('#payway').combogrid('setText',value);
	})
	
	$('#deliveryway').click(function(){
		if(isDeliverywayClick){
			return;
		}
		isDeliverywayClick =true;
		var value =$(this).val();
		$('#deliveryway').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:400,
			width:260,
			idField:'dictionaryID',
			textField:'dictionaryName',
			url:js+'dict/chooseDictionary.action?type=deliveryway',
			columns:[[
				{field:'dictionaryCode',title:'提货方式编号',width:100},
				{field:'dictionaryName',title:'提货方式名称',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if((row.dictionaryCode+row.dictionaryName).toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#deliveryway').combogrid('clear');  $('#deliverywayID').val('');  $('#deliveryway').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#deliveryway').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var deliverywayID = $('#deliveryway').combogrid('getValue');
					var hidden = $('#deliverywayID').val();
					if(hidden==deliverywayID||deliverywayID==''){
						return;
					}
					$('#deliverywayID').val(deliverywayID);
			    }
		});	
		$('#deliveryway').combogrid('setText',value);
	})
	
	$('#shipment').click(function(){
		if(isShipmentClick){
			return;
		}
		isShipmentClick =true;
		var value =$(this).val();
		$('#shipment').combogrid({
			rownumbers:true,
			pagination:true, 
			panelWidth:400,
			width:260,
			idField:'dictionaryID',
			textField:'dictionaryName',
			url:js+'dict/chooseDictionary.action?type=shipment',
			columns:[[
				{field:'dictionaryCode',title:'托运方式编号',width:100},
				{field:'dictionaryName',title:'托运方式名称',width:100},
				{field:'note',title:'备注',width:100}
				
			]],					
			filter:function(q,row){  
				if((row.dictionaryCode+row.dictionaryName).toUpperCase().indexOf(q.toUpperCase())>=0) return true;
			},
			toolbar:[
			 	{text:'清空',iconCls:'icon-no',	handler:function(){ $('#shipment').combogrid('clear');  $('#shipmentID').val('');  $('#shipment').val('');}},
			 	'-',
			 	{text:'确定',iconCls:'icon-ok',handler:function(){$('#shipment').combogrid('hidePanel'); }}]
			 ,onHidePanel:function(){
					var shipmentID = $('#shipment').combogrid('getValue');
					var hidden = $('#shipmentID').val();
					if(hidden==shipmentID||shipmentID==''){
						return;
					}
					$('#shipmentID').val(shipmentID);
			    }
		});	
		$('#shipment').combogrid('setText',value);
	})
		   	    	  	   	    	   
	$('#saleInfor').tabs({
	});
	$('#saleDetailInfor').tabs({
	});
	
	$('#saleCode').dblclick(function(){
		var obj = $(this);
		var saleCode = $(obj).val();
		$.post(js+'common/getCodeCommon.action',{type:'sale',code:saleCode},function(result){
		     if(result.success){
		     		 $('#saleCode').val(result.newCode);
		      }else{
		          $.messager.alert('提示',"自动生成编号失败!!!","error");	
		      }
		},"json");
	})
	
	saleID = $("#saleID").val();
	$('#saleCode').validatebox({
		required:"true" ,
		validType:"remote['"+js+"sale/validateCodeSale.action?saleID="+saleID+"','saleCode']",
		invalidMessage:"该托运单编号已存在"
	})
	
	
	$('#save').click(function (){
		status = $('#status').val();
		
		if(status!='1'){
			 $('#saleForm').form('submit',{
				url: url,
				onSubmit: function(){
					 if($(this).form('validate')){
					 	if(checkGoodsSize()){
					 		$.messager.alert('提示：','货物规格重复','error');
						 	return false;
					 	}else{
					 		preData();
					 		
					 		if(goodsIDArray.length > 0){
					 			$("#goodsIDStr").val(goodsIDArray.join('^^'));
			 				}
			 				if(sizeArray.length > 0){
			 					$("#sizeStr").val(sizeArray.join('^^'));
			 				}
			 				if(weightArray.length > 0){
			 					$("#weightStr").val(weightArray.join('^^'));
			 				}
			 				if(qtyArray.length > 0){
			 					$("#qtyStr").val(qtyArray.join('^^'));
			 				}
			 				if(unitArray.length > 0){
			 					$("#unitStr").val(unitArray.join('^^'));
			 				}
			 				if(volumeArray.length > 0){
			 					$("#volumeStr").val(volumeArray.join('^^'));
			 				}
			 				if(grossWeightArray.length > 0){
			 					$("#grossWeightStr").val(grossWeightArray.join('^^'));
			 				}
			 				
			 				if(feeItemIDArray.length > 0){
			 					$("#feeItemIDStr").val(feeItemIDArray.join('^^'));
			 				}
			 				if(amountArray.length > 0){
			 					$("#amountStr").val(amountArray.join('^^'));
			 				}
			 				if(noteArray.length > 0){
			 					$("#noteStr").val(noteArray.join('^^'));
			 				}
						 	return true;
					 	}
					 }else{
					 	$.messager.alert('提示：','请填写完整信息','error');
					 	return false;
					 }
				},
				success: function(data){
					var result = eval('('+data+')');
					if (result.success){
						saleID=$("#saleID").val();
						if(saleID==''){
							$("#saleID").val(result.saleID);
							saleID=$("#saleID").val();
							$('#saleCode').validatebox({
								required:"true" ,
								validType:"remote['"+js+"sale/validateCodeSale.action?saleID="+saleID+"','saleCode']",
								invalidMessage:"该托运单编号已存在"
							})
							$("#statusStr").val("未确认");
							$("#titleName").html("编辑托运单");
						}
						setUrl();
						$.messager.alert('提示：','保存成功','infor');
					} else {
						$.messager.alert('提示：','保存不成功','error');
					}
				}
			});
		}
		
		return false;
	})
	$('#addSaleDetail').click(function(){
		$(addTRStr()).appendTo($("#saleDetailTable"));
		return false;
	});
	
	$('#deleteSaleDetail').click(function(){
		if(selectRow==null){
	        $.messager.alert("提示!","请选择一行数据!","warning");
	        return;
       	}
	    var the_tr = $("#saleDetailTable tr:eq("+selectRow+")");
	    the_tr.remove();
	    selectRow=null;
		return false;
	});
	
	$('#addSaleFee').click(function(){
		$(addFeeTRStr()).appendTo($("#saleFeeTable"));
		return false;
	});
	
	$('#deleteSaleFee').click(function(){
		if(selectRow==null){
	        $.messager.alert("提示!","请选择一行数据!","warning");
	        return;
       	}
	    var the_tr = $("#saleFeeTable tr:eq("+selectRow+")");
	    the_tr.remove();
	    selectRow=null;
		return false;
	});
	
	
})
function setTitle(){
	var saleID=$("#saleID").val();
	if(saleID!=null&& saleID!=''){
		$("#titleName").html("编辑托运单");
	} 
}


function setUrl(){
	status = $("#status").val();
	if(status==''){
		$("#status").val(0);
		$("#statusStr").val('预录入');
		$('#confirmOK').hide();
		$('#unConfirmOK').hide();
		url = js+'sale/saveSale.action';
	}else{
		if(status == '0'){
			$('#confirmOK').show();	
			$('#unConfirmOK').hide();
		}else{
			$('#unConfirmOK').show();
			$('#confirmOK').hide();	
			$('#save').linkbutton({disabled:true});
		}
		url = js+'sale/updateSale.action';
	}
}

//检查货物规格是否重复 有重复返回true 否则返回false
function checkGoodsSize(){
	 goodsIDArray = new Array();//存放货物ID数组
	 sizeArray = new Array();//存放规格数组
	 weightArray = new Array();//存放重量数组
	 qtyArray = new Array();//存放数量数组
	 unitArray = new Array();//存放度量单位数组
	 volumeArray = new Array();//存放体积数组
	 grossWeightArray = new Array();//存放体积数组
	 
	var the_table = window.document.getElementById('saleDetailTable');
    var goodsSizeArray = new Array();
    /*获得所有货物规格的字符拼接*/
    var goodsID="";
    var size="";

	for(var i = 1 ; i < the_table.rows.length ; i ++){
		goodsID =$(the_table.rows[i].cells[0].children[0]).val();
		size =$(the_table.rows[i].cells[1].children[0]).val();
		weight =$(the_table.rows[i].cells[2].children[0]).val();
		qty =$(the_table.rows[i].cells[3].children[0]).val();
		unit =$(the_table.rows[i].cells[4].children[0]).val();
		var grossWeight =$(the_table.rows[i].cells[5].children[0]).val();
		volume =$(the_table.rows[i].cells[6].children[0]).val();
		goodsIDArray.push(goodsID);
		sizeArray.push(size);
		weightArray.push(weight);
		qtyArray.push(qty);
		unitArray.push(unit);
		volumeArray.push(volume);
		grossWeightArray.push(grossWeight);
		
	    goodsSizeArray.push(goodsID +','+size);
	}
	var len=goodsSizeArray.length;
	for(var i=0;i<len;i++){ 
     for(j=i+1;j<len;j++){
       if(goodsSizeArray[i]==goodsSizeArray[j]){
       	return true;
       }
	 } 
	}
	return false;
}	



function addTRStr(){
	var buffer=new StringBuffer();
	buffer.append('<tr>');
   	buffer.append('<td>');
   	buffer.append('<input type="hidden" id="goodsID_'+addNo+'"   name="goodsID"/> ');
	buffer.append('<input type="text" name = "goods" id="goods_'+addNo+'" style="width:96%;"  onClick="javascript:onSelectGoods(this);" onfocus="changeColor(this)" /> ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "size" style="width:96%;" onfocus="changeColor(this)"/>  ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "weight" class="easyui-numberbox" style="width:96%;" onfocus="changeColor(this)"  onchange="changeWeight(this)" /> ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "qty" style="width:96%;" onfocus="changeColor(this)" onchange="changeQty(this)"/>  ');
   	buffer.append('</td>');
   	buffer.append('<td>');
   	buffer.append('<input type="hidden" id="unitID_'+addNo+'"   name="unitID"/> ');
	buffer.append('<input type="text" name = "unit" id="unit_'+addNo+'" style="width:96%;"  onClick="javascript:onSelectUnit(this);"  onfocus="changeColor(this)"/> ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "grossWeight" style="width:96%;" onfocus="changeColor(this)" onchange="changeGrossWeight(this)"/> ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "volume" style="width:96%;" onfocus="changeColor(this)" onchange="changeVolume(this)"/>  ');
   	buffer.append('</td>');
   
    buffer.append('</tr>');
    addNo++;
    return buffer.toString();
}
var changeWeight = function(obj){
	var weight;
	var weightTotal = 0;
	var table =document.getElementById('saleDetailTable');
	for(var i=1;i<table.rows.length;i++){
		weight = table.rows[i].cells[2].children[0].value;
		if(!isNaN(weight)&&weight!=''){
			weight = parseFloat(weight);
		}else{
			weight = 0;
		}
		weightTotal+=weight;
	}
	$("#weightTotal").val(weightTotal);
}
var changeQty = function(obj){
	var qty;
	var qtyTotal = 0;
	var table =document.getElementById('saleDetailTable');
	for(var i=1;i<table.rows.length;i++){
		qty = table.rows[i].cells[3].children[0].value;
		if(!isNaN(qty)&&qty!=''){
			qty = parseFloat(qty);
		}else{
			qty = 0;
		}
		qtyTotal+=qty;
	}
	$("#qtyTotal").val(qtyTotal);
}
var changeGrossWeight = function(obj){
	var weight;
	var weightTotal = 0;
	var table =document.getElementById('saleDetailTable');
	for(var i=1;i<table.rows.length;i++){
		weight = table.rows[i].cells[5].children[0].value;
		if(!isNaN(weight)&&weight!=''){
			weight = parseFloat(weight);
		}else{
			weight = 0;
		}
		weightTotal+=weight;
	}
	$("#grossWeightTotal").val(weightTotal);
}


var changeVolume = function(obj){
	var volume;
	var volumeTotal = 0;
	var table =document.getElementById('saleDetailTable');
	for(var i=1;i<table.rows.length;i++){
		volume = table.rows[i].cells[6].children[0].value;
		if(!isNaN(volume)&&volume!=''){
			volume = parseFloat(volume);
		}else{
			volume = 0;
		}
		volumeTotal+=volume;
	}
	$("#volumeTotal").val(volumeTotal);
}



var changeColor = function(obj){
	obj.select();
	var tr = $(obj).parents('tr')[0];
	var td =$(obj).parents('td')[0];
	selectTR = tr;
	
	if(tr==null||td==null){
		return;
	}
	clearColor();
	selectRow = tr.rowIndex;
	selectCell = td.cellIndex;
	
	for(var i =0;i<tr.cells.length;i++){
		if(tr.cells[i]!=null){
			var children = $(tr.cells[i]).find('input');
			$(children).each(function(index,item){
				$(item).css('backgroundColor','#e0edfe');
			})
			with(tr.cells[i]){
				style.backgroundColor = '#e0edfe';
			}
		}
	}
}
var clearColor = function(){
	if(selectRow==null){
		return;
	}
	var tr = document.getElementById('saleDetailTable').rows[selectRow];
	for(var i =0;i<tr.cells.length;i++){
		if(tr.cells[i]!=null){
			var children = $(tr.cells[i]).find('input');
			$(children).each(function(index,item){
				$(item).css('backgroundColor','');
			})
			with(tr.cells[i]){
				style.backgroundColor = '';
			}
		}
	}
}

/*选择货物*/
function onSelectGoods(obj){//绑定货物
  if(obj!=null){
	$('#'+obj.id).combogrid({width:195,rownumbers:true, pagination:true,sortOrder:'asc',panelWidth:480,idField:'goodsID',textField:'goodsName',mode:'remote',	//此处需要实时查询，要用remote
        value:obj.id,
		url:js+'dict/chooseGoods.action',
		columns:[[	{field:'goodsName',title:'货物名称',width:130},
		{field:'unitName',title:'默认单位',width:130}	]],	
		toolbar:[{text:'清空',iconCls:'icon-no',	handler:function(){ $('#'+obj.id).combogrid('clear');}				 
		},'-',{	text:'确定',	iconCls:'icon-ok',handler:function(){ $('#'+obj.id).combogrid('hidePanel'); }}]
		,onHidePanel:function(){
			$('#goodsID_'+obj.id.split('_')[1]).val($('#'+obj.id).combogrid('getValue'));
			var unitID=$('#'+obj.id).combogrid('grid').datagrid('getSelected').unitID;
			var unitName=$('#'+obj.id).combogrid('grid').datagrid('getSelected').unitName;
			$('#unitID_'+obj.id.split('_')[1]).val(unitID);
			$('#unit_'+obj.id.split('_')[1]).val(unitName);
			obj.blur();
	    }
	});
  }
}

/*选择度量单位*/
function onSelectUnit(obj){//绑定度量单位
  if(obj!=null){
	$('#'+obj.id).combogrid({width:195,rownumbers:true, pagination:true,sortOrder:'asc',panelWidth:480,idField:'dictionaryID',textField:'dictionaryName',mode:'remote',	//此处需要实时查询，要用remote
        value:obj.id,
		url:js+'dict/chooseDictionary.action?type=Unit',
		columns:[[	{field:'dictionaryName',title:'度量单位名称',width:430}	]],	
		toolbar:[{text:'清空',iconCls:'icon-no',	handler:function(){ $('#'+obj.id).combogrid('clear');}				 
		},'-',{	text:'确定',	iconCls:'icon-ok',handler:function(){ $('#'+obj.id).combogrid('hidePanel'); }}]
		,onHidePanel:function(){
			$('#unitID_'+obj.id.split('_')[1]).val($('#'+obj.id).combogrid('getValue'));
	    }
	});
  }
}

/*选择费用*/
function onSelectFeeItem(obj){//绑定费用
  if(obj!=null){
	$('#'+obj.id).combogrid({width:195,rownumbers:true, pagination:true,sortOrder:'asc',panelWidth:480,idField:'dictionaryID',textField:'dictionaryName',mode:'remote',	//此处需要实时查询，要用remote
        value:obj.id,
		url:js+'dict/chooseDictionary.action?type=saleFeeItem',
		columns:[[	{field:'dictionaryName',title:'费用名称',width:430}	]],	
		toolbar:[{text:'清空',iconCls:'icon-no',	handler:function(){ $('#'+obj.id).combogrid('clear');}				 
		},'-',{	text:'确定',	iconCls:'icon-ok',handler:function(){ $('#'+obj.id).combogrid('hidePanel'); }}]
		,onHidePanel:function(){
			$('#feeItemID_'+obj.id.split('_')[1]).val($('#'+obj.id).combogrid('getValue'));
			obj.blur();
	    }
	});
  }
}

function addFeeTRStr(){
	var buffer=new StringBuffer();
	buffer.append('<tr>');
   	buffer.append('<td>');
   	buffer.append('<input type="hidden" id="feeItemID_'+addFeeNo+'"   name="feeItemID"/> ');
	buffer.append('<input type="text" name ="feeItem" id ="feeItem_'+addFeeNo+'" style="width:96%;"  onClick="javascript:onSelectFeeItem(this);" onfocus="changeColor(this)" /> ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "amount" style="width:96%;" onfocus="changeColor(this)" onchange="changeAmount(this)"/>  ');
   	buffer.append('</td>');
   	buffer.append('<td>');
	buffer.append('<input type="text" name = "note" style="width:96%;" onfocus="changeColor(this)"  /> ');
   	buffer.append('</td>');
    buffer.append('</tr>');
    addFeeNo++;
    return buffer.toString();
}

var changeAmount = function(obj){
	var amount;
	var amountTotal = 0;
	var table =document.getElementById('saleFeeTable');
	for(var i=1;i<table.rows.length;i++){
		amount = table.rows[i].cells[1].children[0].value;
		if(!isNaN(amount)&&amount!=''){
			amount = parseFloat(amount);
		}else{
			amount = 0;
		}
		amountTotal+=amount;
	}
	$("#amountTotal").val(amountTotal);
}


function preData(){
	changeWeight();
	changeQty();
	changeGrossWeight();
	changeVolume();
	changeAmount();
	
	
	 feeItemIDArray = new Array();//存放费用ID数组
	 amountArray = new Array();//存放费用金额数组
	 noteArray = new Array();//存放备注数组
	 
	var the_table = window.document.getElementById('saleFeeTable');
    var feeItemID="";
    var amount="";
    var note="";

	for(var i = 1 ; i < the_table.rows.length ; i ++){
		feeItemID =$(the_table.rows[i].cells[0].children[0]).val();
		amount =$(the_table.rows[i].cells[1].children[0]).val();
		note =$(the_table.rows[i].cells[2].children[0]).val();
		feeItemIDArray.push(feeItemID);
		amountArray.push(amount);
		noteArray.push(note);
	}
}	